<?php

use yii\helpers\Url;
use yii\helpers\Html;
use website\helpers\Render;
use common\models\Recruit;
use common\models\UserCollection;

$this->title = '招聘收藏';
?>
<style>
    #info-table td {padding:10px;}
    #info-table td .flyer-status {margin-right:0 !important;}
</style>

<div class="contenter">
    <?= $this->render('/user/navigator', ['active' => 'collection-recruit-list']) ?>

    <div id="user-contenter">
        <div class="box-shadow pb-20px" id="sub-contenter">
            <div class="data-title"><span class="h3"><?= $this->title ?></span></div>
            <div class="flyer-table simple">
                <table id="info-table" cellspacing="0" cellpadding="0">
                    <tbody>
                    <tr><td colspan="2"><i class="icon-search"></i> 数据加载中，请稍后.</td></tr>
                    </tbody>
                </table>
            </div>
            <div class="flyer-page mt right" id="info-page">
                <div class="html mr-10px"></div>
            </div>
        </div>
    </div>
</div>
<div style="display:none;">
    <?= Render::select('type', Recruit::$typeSelector, null, ['id' => 'recruit-type']) ?>
    <?= Render::select('status', Recruit::$statusSelector, null, ['id' => 'recruit-status']) ?>
</div>

<script src="<?= Render::static('art-template/template.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tabler.class.js') ?>"></script>
<script src="<?= Render::static('flyer/tableHandler.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // 初始化表格异步加载事件
        (new tabler).init({
            // 请求地址
            url: '<?= Url::to('@web/designer/collection-recruit-list') ?>',
            // 数据渲染配置
            table: '#info-table', page: '#info-page', template: 'info-template', search: '#info-search', readyCall: true,
            // param => tabler
            afterPost: function(param) {
                // 充值方式名称显示
                tableHandler.renderCategory({ category: $(param.tabler).find('.type'), select: '#recruit-type' });
                tableHandler.renderCategory({ category: $(param.tabler).find('.status'), select: '#recruit-status' });
                // 初始化 删除按钮事件
                tableHandler.requestSingle({
                    button: $(param.tabler).find('.delete-data'), url: "<?= Url::to('@web/user/collection') ?>", isConfirm: false,
                    beforePost: function(params) {
                        params.data = { handle: $(params.mthis).attr('data-handle'), id: $(params.tr).attr('data-id'), type: '<?= UserCollection::TypeRecruit ?>' };
                    },
                    requestSuccess: function(params) {
                        if($(params.mthis).attr('data-handle') == 'collection') {
                            $(params.mthis).attr('data-handle', 'revoke').html('取消收藏');
                        }
                        else {
                            $(params.mthis).attr('data-handle', 'collection').html('加入收藏');
                        }
                    }
                });
            }
        });
    });
</script>
<script id="info-template" type="text/html">
    {{if infos != undefined && infos.length}}
    {{each infos as info key}}
    <tr id="tr-{{info.collection_id}}" data-id="{{info.collection_id}}">
        <td class="first">
            <p><a href="<?= Url::to('@web/seer/recruit?id=') ?>{{info.collection_id}}">{{info.recruit.title}}</a></p>
            <p>
                <span>发布日期：{{info.recruit.created_at | dateShow: format = 'day'}}</span>
                <span class="ml-20px">状态：<span class="status">{{info.recruit.status}}</span></span>
            </p>
        </td>
        <td class="tar">
            <p><span class="type">{{info.recruit.type}}</span></p>
            <p><button class="delete-data flyer-button normal border-round narrow thin" data-handle="revoke">取消收藏</button></p>
        </td>
    </tr>
    {{/each}}
    {{else}}
    <tr>
        <td class="first" colspan="2"><i class="icon-ban-circle"></i> 搜索程序未为您搜索到任何信息！</td>
    </tr>
    {{/if}}
</script>